<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>回调</title>

  <!--引入vue + axios-->
  <script src="js/plugins/vue/dist/vue.js"></script>
  <script src="js/plugins/axios/dist/axios.js"></script>
  <!--全局使用-->
  <script src="js/common.js"></script>
</head>
<body>
<div id="myDiv">

</div>

</body>
<script type="text/javascript">
  new Vue({
    el:"#myDiv",
    mounted(){
      //1.解析参数
      let url = location.href;
      let paramObj = parseUrlParams2Obj(url);
      //2.发送axios请求 微信登录接口  携带扫码授权后微信返回的code作为用户的唯一标识
      this.$http.post("/login/wechat",{"code":paramObj.code})
              .then(result=>{
                result = result.data;//AjaxResult
                if(result.success){//说明是第2---n次扫码，直接登录成功
                  localStorage.setItem("token",result.resultObj.token);//UUID的随机串
                  //注意：需要将返回的JSON对象转换成JSON字符串存储
                  localStorage.setItem("user",JSON.stringify(result.resultObj.user));
                  //登录成功，跳转到首页
                  location.href = "index.html";
                }else{//跳转到绑定页面
                  let binderUrl = "binder.html"+result.resultObj;
                  location.href = binderUrl;
                }
              })
              .catch(result=>{
                alert("哦豁！！！")
              })
    }
  })
</script>
</html>